<template>
	<view class="classlist">
		<view class="loading" v-if="!classList.length && !noData">
			<uni-load-more status="loading" />
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id='+item._id" class="item" v-for="item in classList" :key="item._id">
				<image :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
		<view class="loading" v-if="classList.length || noData">
			<uni-load-more :status="noData ? 'noMore':'loading'" />
		</view>
		<view class="safe-area-inset-bottom"></view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { GetApiClassList, GetApiHistoryList } from "@/api/api.js"
import { onLoad,onUnload,onReachBottom,onPullDownRefresh,onShareAppMessage,onShareTimeline} from "@dcloudio/uni-app";
import { gotoHome } from "@/utils/common.js"
const noData = ref(false)
const queryParams = {
	pageNum: 1,
	pageSize: 12
}
let shareName = null
onPullDownRefresh(()=>{
	queryParams.pageNum = 1
	classList.value = []
	getClassList()
})
onLoad((e)=>{
	let {id = null,name = null,type = null}= e;
	//if (!id) {gotoHome()}
	if (type) {
		queryParams.type = type
	}
	if (id) {
		queryParams.classid = id
	}
	shareName = name
	console.log(id,name)
	uni.setNavigationBarTitle({
		title:e.name
	})
	
	getClassList()
})
onUnload(()=>{
	uni.removeStorage({
		key:"storgClassList"
	})
})

onReachBottom((e)=>{
	if (noData.value) return;
	queryParams.pageNum++
	getClassList()
	console.log(123123123)
})
const classList = ref([])

const getClassList = async()=>{
	let res;
	if (queryParams.classid) {
		res = await GetApiClassList(queryParams)
	}
	if (queryParams.type) {
		res = await GetApiHistoryList(queryParams)
	}
	classList.value = [...classList.value,...res.data.data]
	if (queryParams.pageSize > res.data.data.length) {
		noData.value = true
	}
	uni.stopPullDownRefresh()
	uni.setStorageSync("storgClassList",classList.value)
	
}


//分享给好友
onShareAppMessage((e)=>{
	console.log(e)
	return {
		title:"@@@",
		path:"/pages/classlist/classlist?id="+queryParams.classid+"&name="+shareName
	}
})
//分享朋友圈
onShareTimeline(()=>{
	return {
		title:"咸虾米壁纸~~~",
		query: "id="+queryParams.classid+"&name="+shareName
	}
})
   

</script>

<style lang="scss" scoped>
.classlist {
	.content {
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		padding: 5rpx;
		.item {
			height: 400rpx;
			image {
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
